package cn.congzhou.crm.service.impl;

import cn.congzhou.crm.domain.Customer;
import cn.congzhou.crm.domain.FormalCustomer;
import cn.congzhou.crm.domain.SystemDictionaryItem;
import cn.congzhou.crm.mapper.FormalCustomerMapper;
import cn.congzhou.crm.query.QueryObject;
import cn.congzhou.crm.service.IFormalCustomerService;
import cn.congzhou.crm.service.ISystemDictionaryItemService;
import cn.congzhou.crm.utils.UserContext;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class FormalCustomerServiceImpl implements IFormalCustomerService {

    @Autowired
    private FormalCustomerMapper formalCustomerMapper;


//  插入正式客户
    @Override
    public int insert(FormalCustomer entity) {
        entity.setVdate(new Date());
        entity.setSeller(UserContext.getCurrentUser());
        formalCustomerMapper.insert(entity);

        return 0;
    }

    @Override
    public PageInfo<FormalCustomer> selectByPage(QueryObject qo) {
//      分页前的处理，分页参数
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize());
        List<FormalCustomer> formalCustomers = formalCustomerMapper.selectByPage(qo);
//      把查询到的数据封装成pageInfo对象
        PageInfo<FormalCustomer> pageInfo = new PageInfo<>(formalCustomers);
        return pageInfo;
    }

//  查询所有客户
    @Override
    public List<Customer> selectAllCustomer(Integer statusFormal) {
        List<Customer> customers = formalCustomerMapper.selectAllCustomer(statusFormal);

        return customers;
    }

}
